package com.system.manager.modules.authorized.service.impl;

import com.system.manager.common.exception.SysException;
import com.system.manager.modules.authorized.entity.MenuKey;
import com.system.manager.modules.authorized.entity.SysMenu;
import com.system.manager.modules.authorized.entity.SystemMenu;
import com.system.manager.modules.authorized.mapper.SysMenuRepository;
import com.system.manager.modules.authorized.mapper.SystemMenuMapper;
import com.system.manager.modules.authorized.service.ISystemMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.manager.modules.authorized.vo.MenuVo;
import com.system.manager.utils.TreeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.SystemException;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统菜单表 服务实现类
 * </p>
 *
 * @author yxp
 * @since 2021-10-18
 */
@Transactional
@Service
public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenu> implements ISystemMenuService {

    @Override
    public List<SystemMenu> selectMenuList() {

        List<SystemMenu> menus = new ArrayList<>();

        try {
            menus = list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new SysException();
        }

        for (SystemMenu menu : menus) {
            if (0 == menu.getPid()) {
                menu.setPid(-1);
            }
        }
        return menus;
    }

}
